package com.supermap.business.cloud.meto;

import com.alibaba.dubbo.config.annotation.Reference;
import com.supermap.dataservice.redis.JedisComponent;
import com.supermap.dataservice.util.JSONUtils;
import com.supermap.dubbo.api.cloud.meto.MetoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author aqua
 * @descriptiongetFarmDateTime
 * @date 2019年12月31 17:20
 * @email 1301584033@qq.com
 */
@Controller
@RequestMapping("/cloud/meto")
public class MetoController {
    @Reference(timeout = 100000)
    private MetoService metoService;

    @Autowired
    JedisComponent jedisComponent;


    @GetMapping("/getFrecastDataList")
    @ResponseBody
    //预报
    public JSONUtils getFrecastDataList(String areaCode,String lat,String lon){
        String key="/cloud/meto/getMenuGroupByCountList"+areaCode+lat+lon;
        JSONUtils jsonUtils=null;
        if(jedisComponent.exists(key)){
            jsonUtils=new JSONUtils().setData(jedisComponent.getObject(key));
            return  jsonUtils;
        }else{
            jsonUtils=metoService.getFrecastDataList(areaCode,lat,lon);
        }
        //设置缓存
        jedisComponent.setObject(key,jsonUtils.getData());
        //设置时效 保存半个小时
        jedisComponent.setKeyTime(key,3600*3);
        //设置时效 保存半个小时
        return jsonUtils;
    }

    //生活指数
    @GetMapping("/getLifeInfo")
    @ResponseBody
    public JSONUtils getLifeInfo(String areaCode,String lat,String lon){
        String key="/cloud/meto/getLifeInfo"+areaCode+lat+lon;
        JSONUtils jsonUtils=null;
        if(jedisComponent.exists(key)){
            jsonUtils=new JSONUtils().setData(jedisComponent.getObject(key));
            return  jsonUtils;
        }else{
            jsonUtils=metoService.getLifeInfo(areaCode,lat,lon);
        }
        //设置缓存
        jedisComponent.setObject(key,jsonUtils.getData());
        //设置时效 保存半个小时
        jedisComponent.setKeyTime(key,3600*3);
        //设置时效 保存半个小时
        return jsonUtils;
    }
    //实况
    @GetMapping("/getWeatherDataList")
    @ResponseBody
    public String getWeatherDataList(String areaCode,String lat,String lon){
        String key="/cloud/meto/getWeatherDataList"+areaCode+lat+lon;
        String jsonUtils=null;
        if(jedisComponent.exists(key)){
            jsonUtils=(String) jedisComponent.getObject(key);
            return  jsonUtils;
        }else{
            jsonUtils=metoService.getWeatherDataList(areaCode,lat,lon);
        }
        //设置缓存
        jedisComponent.setObject(key,jsonUtils);
        //设置时效 保存半个小时
        jedisComponent.setKeyTime(key,600);
        //设置时效 保存半个小时
        return jsonUtils;
    }

    //历史同期
    @GetMapping("/getSurfchndayList")
    @ResponseBody
    public JSONUtils getSurfchndayList(String areaCode,String lat,String lon){
        String key="/cloud/meto/getSurfchndayList"+areaCode+lat+lon;
        JSONUtils jsonUtils=null;
        if(jedisComponent.exists(key)){
            jsonUtils=new JSONUtils().setData(jedisComponent.getObject(key));
            return  jsonUtils;
        }else{
            jsonUtils=metoService.getSurfchndayList(areaCode,lat,lon);
        }
        //设置缓存
        jedisComponent.setObject(key,jsonUtils.getData());
        //设置时效 保存半个小时
        jedisComponent.setKeyTime(key,3600*3);
        //设置时效 保存半个小时
        return jsonUtils;
    }


    //历史
    @GetMapping("/getPubertyDate")
    @ResponseBody
    public JSONUtils getPubertyDate(String crop){
        return  metoService.getPubertyDate(crop);
    }
    //当年
    @GetMapping("/getYearPubertyDate")
    @ResponseBody
    public JSONUtils getYearPubertyDate(String crop){
        return  metoService.getPubertyDate(crop);
    }


    //土壤商情分布图
    @GetMapping("/getGridProduct")
    @ResponseBody
    public JSONUtils getGridProduct(String areaCode,String data,String gridCode){
        return  metoService.getGridProduct(areaCode,data,gridCode);
    }

    //物联网分布图
    @GetMapping("/getVendorList")
    @ResponseBody
    public JSONUtils getVendorList(String areaCode){
        return  metoService.getVendorList(areaCode);
    }

    //我的气象土壤商情
    @GetMapping("/getGridList")
    @ResponseBody
    public String getGridList(String areaCode,String lat,String lon,String date){
        return  metoService.getGridList(areaCode,lat,lon,date);
    }
    //好产品
    @GetMapping("/getGoodProduct")
    @ResponseBody
    public JSONUtils getGoodProduct(String areaCode){
        return  metoService.getGoodProduct(areaCode);
    }

    // 疑似火点
    @GetMapping("/getFiremonitor")
    @ResponseBody
    public JSONUtils getFiremonitor(String areaCode,String date){
        return  metoService.getFiremonitor(areaCode,date);
    }

    // 风险灾害区划类型
    @GetMapping("/getDisasteRiskType")
    @ResponseBody
    public JSONUtils getDisasteRiskType(){
        return  metoService.getDisasteRiskType();
    }

    //获取5天预报(专家经验产品)
    @GetMapping("/get5DayForcast")
    @ResponseBody
    public JSONUtils get5DayForcast(){
        return  metoService.get5DayForcast();
    }

    //获取5天历史(专家经验产品)
    @GetMapping("/get5DayHistory")
    @ResponseBody
    public String get5DayHistory(){
        return  metoService.get5DayHistory();
    }

    // 气候资源类型
    @GetMapping("/getClimaticResourcesType")
    @ResponseBody
    public JSONUtils getClimaticResourcesType(){
        return  metoService.getClimaticResourcesType();
    }

    /**
     * 获取一张图二级数据菜单
     */
    @GetMapping("/getOneMapSecondMenuType")
    @ResponseBody
    public JSONUtils getOneMapSecondMenuType(String code){
        return  metoService.getOneMapSecondMenuType(code);
    }

}
